//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    reasonArr: [{
        value: '卖家长时间不发货',
        checked: false
      },
      {
        value: '重新购买',
        checked: false
      },
      {
        value: '买错商品',
        checked: false
      },
      {
        value: '对产品不满意',
        checked: false
      },
      {
        value: '其他',
        checked: false
      },
    ],
    describe:"",
    // 
    uid:"",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // console.log(options);
    this.setData({
      uid: wx.getStorageSync('uid'),
      orderNumber : options.orderNum
    })

  },

  // 
  chooseReason: function(e) {
    console.log(e);
    var that = this;
    var reasonArr = this.data.reasonArr;
    var describe = this.data.describe;
    var value = e.currentTarget.dataset.value;
    for (var i = 0, len = reasonArr.length; i < len; ++i) {
      if (reasonArr[i].value == value) {
        reasonArr[i].checked = true;
      } else {
        reasonArr[i].checked = false
      }
    }
    this.setData({
      value: value,
      reasonArr: reasonArr,
      describe: e.currentTarget.dataset.value

    })

  },
  // 提交申请
  submitTap: function() {
    var that = this;
    var uid = this.data.uid;
    var orderNumber = this.data.orderNumber;
    var describe = this.data.describe;
    if(describe == ""){
      wx.showToast({
        title: "请选择退款原因！",
        icon: 'none',
        duration: 2000
      });
      return false;
    }
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=OrderRefund&UID=" + uid + "&OrderNumber=" + orderNumber + "&Describe=" + describe),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        if (json.ResultData == "success"){
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          setTimeout(function () {
            wx.navigateTo({
              url: '/packageA/mailOrder/mailOrder',
            })
          }, 500)
       }else{
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
       }
        console.log(json);
      }
    })
  },
  // 
})